package com.gh.ok.ui

import android.os.Bundle
import android.view.View
import com.gh.ok.R
import com.gh.ok.databinding.ActivityCoilDemoBinding
import com.gyf.immersionbar.ktx.immersionBar
import com.ok.common.base.BaseActivity
import com.ok.common.enum.ShapeType
import com.ok.common.ext.dp
import com.ok.common.ext.loadImage

/**
 * 基于Coil扩展函数的图片加载Sample
 * - 支持加载网络图片、本地图片、Gif动画
 * - shapeType：NONE, ROUND, RECTANGLE
 * - radius：圆角度数，仅shapeType为RECTANGLE设置有效
 * - duration：渐变加载时间
 * - repeatCount：Gif播放次数
 * - transformation支持自定义转换
 */
class CoilSampleActivity : BaseActivity<ActivityCoilDemoBinding>() {

    companion object {
        private const val IMAGE_URL =
            "https://ww2.sinaimg.cn/mw690/77b685fbgy1htcoot5wnij21t43wzkjv.jpg"

    }

    override fun initImmersionBar() {
        immersionBar {
            titleBar(mBinding.viewTitle.titleBar)
            navigationBarColor(R.color.bgHomeTab)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        mBinding.apply {
            viewTitle.tvTitle.text = intent.extras?.getString("title")
            iv.loadImage(IMAGE_URL, shapeType = ShapeType.RECTANGLE, radius = 20F.dp)
            ivGif.loadImage(R.raw.gif_guide)
        }
    }

    override fun initListener() {
        super.initListener()
        mBinding.viewTitle.ibtnBack.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.ibtn_back -> {
                finish()
            }
        }
    }

}